package cn.edu.ahu.aircondition.modbus.service.domain;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询结果Domain
 * Created by ahu on 2017/6/8.
 */
public class QueryRegDomain {
    private Integer deviceAddress;
    private String aoc;
    private String airConCtrlTemp;
    private String envTemp;
    private String model;
    private String wind;
    private String errMsg;
    private List<Integer> coilsDataList = new ArrayList<Integer>();
    private List<Integer> inpRegDataList = new ArrayList<Integer>();

    public QueryRegDomain(Integer deviceAddress, List<Integer> coilsDataList,List<Integer> inpRegDataList) {
        this.deviceAddress = deviceAddress;
        this.coilsDataList = coilsDataList;
        this.inpRegDataList = inpRegDataList;
        this.errMsg = "无";
        setAoc();
        setModel();
        setAirConCtrlTemp();
        setWind();
        setEnvTemp();
        setErrMsg();

    }

    private void setAoc() {
        if (coilsDataList.get(7) == 1)
            this.aoc = "开机";
        if (coilsDataList.get(7) == 0)
            this.aoc = "关机";
    }

    private void setModel() {
        if (coilsDataList.get(0) == 1)
            this.model = "送风";
        if (coilsDataList.get(1) == 1)
            this.model = "除湿";
        if (coilsDataList.get(2) == 1)
            this.model = "制热";
        if (coilsDataList.get(3) == 1)
            this.model = "制冷";
        if (coilsDataList.get(4) == 1)
            this.model = "自动";
        else
            this.model = "自动";
    }

    public void setAirConCtrlTemp() {
        this.airConCtrlTemp = String.valueOf(inpRegDataList.get(0));
    }

    private void setWind() {
        if (coilsDataList.get(8) == 1)
            this.wind = "高风";
        if (coilsDataList.get(9) == 1)
            this.wind = "中风";
        if (coilsDataList.get(10) == 1)
            this.wind = "低风";
        if (coilsDataList.get(11) == 1)
            this.wind = "微风";
        if (coilsDataList.get(15) == 1)
            this.wind = "自动";
        else
            this.wind = "自动";
    }

    public void setEnvTemp() {
        this.envTemp = String.valueOf(inpRegDataList.get(1));
    }

    private void setErrMsg() {
        if (coilsDataList.get(40) == 1)
            errMsg += "E0 相序错或缺相 ；";
        if (coilsDataList.get(41) == 1)
            errMsg += "E1 通讯故障；";
        if (coilsDataList.get(42) == 1)
            errMsg += "E2 T1传感器故障；";
        if (coilsDataList.get(43) == 1)
            errMsg += "E3 T2A传感器故障；";
        if (coilsDataList.get(44) == 1)
            errMsg += "E4 T2B传感器故障；";
        if (coilsDataList.get(45) == 1)
            errMsg += "E5 T3或者T4或者数码压缩机排气温度传感器故障；";
        if (coilsDataList.get(46) == 1)
            errMsg += "E6 过零检测错；";
        if (coilsDataList.get(47) == 1)
            errMsg += "E7 EEPROM出错；";
        if (coilsDataList.get(48) == 1)
            errMsg += "E8 风速检测失控；";
        if (coilsDataList.get(49) == 1)
            errMsg += "E9 主板与显示板通；";
        if (coilsDataList.get(50) == 1)
            errMsg += "EA 压缩机过流；";
        if (coilsDataList.get(51) == 1)
            errMsg += "EB 变频模块保护；";
        if (coilsDataList.get(52) == 1)
            errMsg += "EC 清新故障；";
        if (coilsDataList.get(53) == 1)
            errMsg += "ED 室外故障保护；";
        if (coilsDataList.get(54) == 1)
            errMsg += "EE 水位检测故障；";
        if (coilsDataList.get(55) == 1)
            errMsg += "EF 其他故障；";
        if (coilsDataList.get(72) == 1)
            errMsg += "0# 网络接口模块与主控板通讯故障；";
        if (coilsDataList.get(73) == 1)
            errMsg += "1# 集中监控器与网络接口模块故障；";
        if (coilsDataList.get(74) == 1)
            errMsg += "2# 集中监控器与功能模块通讯故障；";
        if (coilsDataList.get(75) == 1)
            errMsg += "3# 集中监控器与计 算机（网关）通讯 故障；";
        if (coilsDataList.get(76) == 1)
            errMsg += "4# 命令限制执行；";
        if (coilsDataList.get(77) == 1)
            errMsg += "5# 命令超时，未执行；";
        if (coilsDataList.get(78) == 1)
            errMsg += "6# 目的地址不存在；";
        if (coilsDataList.get(79) == 1)
            errMsg += "7# 错误（不支持）的命令；";
    }

    public Integer getDeviceAddress() {
        return deviceAddress;
    }

    public String getAoc() {

        return aoc;
    }

    public String getModel() {
        return model;
    }

    public String getAirConCtrlTemp() {
        return this.airConCtrlTemp;
    }

    public String getWind() {
        return wind;
    }

    public String getEnvTemp() {
        return this.envTemp;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public List<Integer> getCoilsDataList() {
        return coilsDataList;
    }

    public List<Integer> getInpRegDataList() {
        return inpRegDataList;
    }
}
